#include<stdio.h>
int romanToInt(char *s)
{
    int i = 0;
    int sum = 0;
    int *num = (int *)malloc(sizeof(int) * strlen(s));
    for (i = 0; i < strlen(s); ++i)
    {
        switch (s[i])
        {
        case 'I':
            num[i] = 1;
            break;
        case 'V':
            num[i] = 5;
            break;
        case 'X':
            num[i] = 10;
            break;
        case 'L':
            num[i] = 50;
            break;
        case 'C':
            num[i] = 100;
            break;
        case 'D':
            num[i] = 500;
            break;
        case 'M':
            num[i] = 1000;
            break;
        }
    }
    sum += num[strlen(s) - 1];
    for (i = strlen(s) - 2; i >= 0; --i)
    {
        if (num[i] < num[i + 1] && i > 0)
        {
            sum -= num[i];
            sum += num[i - 1];
            i--;
        }
        else if (i > 0)
        {
            sum += num[i];
        }
        else
        {
            if (num[i] < num[i + 1])
            {
                sum -= num[i];
            }
            else
            {
                sum += num[i];
            }
        }
    }
    return sum;
}